package ma.ensao.evalmetrics.util.javaProjects;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
import com.thoughtworks.qdox.model.JavaMethod;

//Classe pour les methodes et les attributs
public class JavaMethodsAttributes {
	File sourceFile;
	JavaClasses javaClasses;
	JavaClass[] classes;
	JavaMethod[][] methods;
	String[][] methodsCode;
	JavaField[][] attributes;
	int NumberClasses;
	int[] NumberProtectedMethods;
	int[] NumberPrivateMethods;
	int[] NumberPrivateAttributes;
	int[] NumberStaticMethods;
	int[] NumberPublicMethods;
	int[] NumberMethods;
	public String[][] getMethodsCode() {
		return methodsCode;
	}
	public void setMethodsCode(String[][] methodsCode) {
		this.methodsCode = methodsCode;
	}
	//Definie les methodes
	public JavaMethodsAttributes( File file) throws FileNotFoundException, IOException {
		this.setJavaClasses(new JavaClasses(file));
		javaClasses.ClassesNames();
		classes= javaClasses.getClassesNames();
		javaClasses.MethodsNames(classes);
		methods= javaClasses.getClassesMethodsNames();
		javaClasses.attributesNames(classes);
		attributes= javaClasses.getClassesAttributesNames();
		
		String[][] methodsCode= new String[classes.length][];
		for (int i = 0; i < classes.length; i++) {
			for(int j=0; j<methods[i].length; j++){
				methodsCode[i]= new String[methods[i].length];
				System.out.println(methodsCode[i].length);
			}
		}
		this.setMethodsCode(methodsCode);
	}
	public JavaField[][] getAttributes() {
		return attributes;
	}
	public void setAttributes(JavaField[][] attributes) {
		this.attributes = attributes;
	}
	public int[] getNumberProtectedAttributes() {
		return NumberProtectedAttributes;
	}
	public void setNumberProtectedAttributes(int[] numberProtectedAttributes) {
		NumberProtectedAttributes = numberProtectedAttributes;
	}
	public int[] getNumberAttributes() {
		return NumberAttributes;
	}
	public void setNumberAttributes(int[] numberAttributes) {
		NumberAttributes = numberAttributes;
	}
	int[] NumberProtectedAttributes;
	int[] NumberAttributes;
	 //Calculer le nombre des methodes protected
	public void countProtectedMethods() {
		NumberClasses= classes.length;
		NumberProtectedMethods= new int[classes.length];
		for (int i = 0; i < NumberClasses; i++) {
			for (int j = 0; j < methods[i].length; j++) {
				if (methods[i].length == 0){
					NumberProtectedMethods[i]=0;
				}else{
					if ( methods[i][j].isProtected()){
						NumberProtectedMethods[i]++;
				}
				}
			}
		}
	}
	//Calculer le nombre des methodes
	 
	public void countMethods() {
		NumberClasses= classes.length;
		NumberMethods= new int[classes.length];
		for (int i = 0; i < NumberClasses; i++) {
			if(methods[i].length == 0){
				NumberMethods[i]=0;
			}else{
				NumberMethods[i]= methods[i].length;				
			}
		}
	}

	public int getNumberClasses() {
		return NumberClasses;
	}
	public void setNumberClasses(int numberClasses) {
		NumberClasses = numberClasses;
	}
	public File getSourceFile() {
		return sourceFile;
	}

	public void setSourceFile(File sourceFile) {
		this.sourceFile = sourceFile;
	}

	public JavaClasses getJavaClasses() {
		return javaClasses;
	}

	public void setJavaClasses(JavaClasses javaClasses) {
		this.javaClasses = javaClasses;
	}

	public int[] getNumberProtectedMethods() {
		return NumberProtectedMethods;
	}

	public void setNumberProtectedMethods(int[] numberprotectedMethods) {
		NumberProtectedMethods = numberprotectedMethods;
	}

	public int[] getNumberMethods() {
		return NumberMethods;
	}

	public void setNumberMethods(int[] numbermethods) {
		NumberMethods = numbermethods;
	}
	public JavaClass[] getClasses() {
		return classes;
	}
	public void setClasses(JavaClass[] classes) {
		this.classes = classes;
	}
	public JavaMethod[][] getMethods() {
		return methods;
	}
	public void setMethods(JavaMethod[][] methods) {
		methods = methods;
	}
	//Calculer le nombre des attributs protected
	public void countProtectedAttributes() {
		NumberClasses= classes.length;
		NumberProtectedAttributes= new int[classes.length];
		for (int i = 0; i < NumberClasses; i++) {
			for (int j = 0; j < attributes[i].length; j++) {
				if (attributes[i].length == 0){
					NumberProtectedAttributes[i]=0;
				}else{
					if (attributes[i][j].isProtected()){
						NumberProtectedAttributes[i]++;
					}
				}
			}
		}
	}
	//Calculer le nombre des attributs private
	 
	public void countPrivateAttributes() {
		NumberClasses= classes.length;
		NumberPrivateAttributes= new int[classes.length];
		for (int i = 0; i < NumberClasses; i++) {
			for (int j = 0; j < attributes[i].length; j++) {
				if (attributes[i].length == 0){
					NumberPrivateAttributes[i]=0;
				}else{
					if (attributes[i][j].isPrivate()){
						NumberPrivateAttributes[i]++;
					}
				}
			}
		}
	}
	
	public int[] getNumberPrivateAttributes() {
		return NumberPrivateAttributes;
	}
	public void setNumberPrivateAttributes(int[] numberPrivateAttributes) {
		NumberPrivateAttributes = numberPrivateAttributes;
	}
	
	//Calculer le nombre des attributs 
	 
	public void countAttributes() {
		NumberClasses= classes.length;
		NumberAttributes= new int[classes.length];
		for (int i = 0; i < NumberClasses; i++) {
			if(attributes[i].length == 0){
				NumberAttributes[i]=0;
			}else{
				NumberAttributes[i]= attributes[i].length;
			}
		}
	}
	//Calculer le nombre des methodes private
	 
	public void countPrivateMethods() {
		NumberClasses= classes.length;
		NumberPrivateMethods= new int[classes.length];
		for (int i = 0; i < NumberClasses; i++) {
			for (int j = 0; j < methods[i].length; j++) {
				if (methods[i].length == 0){
					NumberPrivateMethods[i]=0;
				}else{
					if ( methods[i][j].isPrivate()){
						NumberPrivateMethods[i]++;
				}
				}
			}
		}
	}
	
	public void countStaticMethods() {
		NumberClasses= classes.length;
		NumberStaticMethods= new int[classes.length];
		for (int i = 0; i < NumberClasses; i++) {
			for (int j = 0; j < methods[i].length; j++) {
				if (methods[i].length == 0){
					NumberStaticMethods[i]=0;
				}else{
					if ( methods[i][j].isStatic()){
						NumberStaticMethods[i]++;
				}
				}
			}
		}
	}
	
	
	public void countPublicMethods() {
		NumberClasses= classes.length;
		NumberPublicMethods= new int[classes.length];
		for (int i = 0; i < NumberClasses; i++) {
			for (int j = 0; j < methods[i].length; j++) {
				if (methods[i].length == 0){
					NumberPublicMethods[i]=0;
				}else{
					if ( methods[i][j].isPublic()){
						NumberPublicMethods[i]++;
				}
				}
			}
		}
	}
	
	public int[] getNumberPrivateMethods() {
		return NumberPrivateMethods;
	}
	public void setNumberPrivateMethods(int[] numberPrivateMethods) {
		NumberPrivateMethods = numberPrivateMethods;
	}
	public void methodCode(){
		for (int i = 0; i < classes.length; i++) {
			for(int j=0; j<methods[i].length; j++){
				methodsCode[i][j]= methods[i][j].getCodeBlock();
			}
		}
	}
	public int[] getNumberStaticMethods() {
		return NumberStaticMethods;
	}
	public void setNumberStaticMethods(int[] numberStaticMethods) {
		NumberStaticMethods = numberStaticMethods;
	}
	public int[] getNumberPublicMethods() {
		return NumberPublicMethods;
	}
	public void setNumberPublicMethods(int[] numberPublicMethods) {
		NumberPublicMethods = numberPublicMethods;
	}
	
}
